package com.guragura.util;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;

/**
 * Manages game data
 * 
 * @author Rendy Bambang Junior
 * 
 */
public class GuraGameData {

	public static int lastlevel=1;
	public static int highscore=0;

	public static void loadData() {
		Preferences pref = Gdx.app.getPreferences("gamedata");
		if (pref != null) {
			if (!pref.getBoolean("setup")) {
				// first start
				
				resetDefaultData();
				loadSavedData();
				pref.putBoolean("setup",true);

			} else {
				// next start
				loadSavedData();
			}
		}
	}


	public static void loadSavedData() {
		Preferences pref = Gdx.app.getPreferences("gamedata");
		if (pref != null) {
			lastlevel = pref.getInteger("lastlevel");
			highscore = pref.getInteger("highscore");	
		}
	}

	public static void resetDefaultData() {
		Preferences pref = Gdx.app.getPreferences("gamedata");
		if (pref != null) {
			pref.putInteger("lastlevel", 1);
			pref.putInteger("highscore", 0);	
		}

	}

	public static void saveSettings() {
		Preferences pref = Gdx.app.getPreferences("gamedata");
		if (pref != null) {
			pref.putInteger("lastlevel", lastlevel);
			pref.putInteger("highscore", highscore);	
		}
	}
}
